/**
 * 提示与加载工具类
 */
import G_show_modal from '@/components/G_show_modal/g_show_modal.js'
import Vue from 'vue'
// Vue.use(G_show_modal)
export default class Tips {
	constructor() {
		this.isLoading = false;
	}

	/**
	 * 弹出加载提示
	 */
	static loading(title = "正在加载") {
		if (Tips.isLoading) {
			return;
		}
		Tips.isLoading = true;
		uni.showLoading({
			title: title,
			mask: true
		});
	}

	/**
	 * 加载完毕
	 */
	static loaded() {
		if (Tips.isLoading) {
			setTimeout(() => {
				Tips.isLoading = false;
				uni.hideLoading();
			}, 300)
		}
	}

	static toast(msg, icon = "none", duration = 2000) {
		uni.showToast({
			title: msg,
			duration: duration,
			icon: icon
		})
	}
	
	static success(msg, duration = 2000) {
		uni.showToast({
			title: msg,
			duration: duration,
			icon: 'success'
		})
	}

	/**
	 * 模态弹窗
	 * type: alert '提示框'  confirm:'确认框'
	 */
	static modal(op = {
		title,
		content,
		showCancel: true,
		confirmText: '确认'
	}) {
		let {
			title,
			content,
			showCancel,
			confirmText
		} = op
		title = title || '提示'

		return new Promise((resolve, reject) => {
			// #ifdef APP-PLUS
			// 安卓使用另外的样式框架
			switch (uni.getSystemInfoSync().platform) {

				case 'android':
					// console.log(G_show_modal.show({concent:'是否退出登录123~'}))
					G_show_modal.show({
						title: title,
						concent: content,
						confirmColor: '#7B4EFF',
						delCancel: showCancel ? true : false
					}).then(res => {
						console.log(res)
						resolve();
						//确认
					}).catch(res => {
						reject();
						//取消
					})
					break;
				default:
					uni.showModal({
						title: title,
						content: content,
						confirmColor: '#7B4EFF',
						showCancel: showCancel,
						confirmText: confirmText,
						success: function(res) {
							if (res.confirm) {
								resolve();
							} else if (res.cancel) {
								reject();
							}
						}
					});
					break;
			}
			// #endif
			// #ifndef APP-PLUS
			uni.showModal({
				title: title,
				content: content,
				confirmColor: '#7B4EFF',
				showCancel: showCancel,
				confirmText: confirmText,
				success: function(res) {
					if (res.confirm) {
						resolve();
					} else if (res.cancel) {
						reject();
					}
				}
			});
			// #endif

		})
	}

}
/**
 * 静态变量，是否加载中
 */
Tips.isLoading = false;